package com.nuoniu.sibanyun.service.erp.barcode.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.dto.BarcodeMainInfoSearchDto;
import com.nuoniu.sibanyun.entity.erp.barcode.ErpBarcodePrintDetail;
import com.nuoniu.sibanyun.mapper.erp.barcode.ErpBarcodePrintDetailMapper;
import com.nuoniu.sibanyun.service.erp.barcode.IErpBarcodePrintDetailService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 条码管理-打印管理-条码明细 服务实现类
 * </p>
 *
 * @author 白强
 * @since 2021-11-10
 */
@Service
public class ErpBarcodePrintDetailServiceImpl extends ServiceImpl<ErpBarcodePrintDetailMapper, ErpBarcodePrintDetail> implements IErpBarcodePrintDetailService {

    @Override
    public ErpBarcodePrintDetail getByCondition(BarcodeMainInfoSearchDto barcodeMainInfoSearchDto) {
        Long ruleId = barcodeMainInfoSearchDto.getRuleId();
        String barcode = barcodeMainInfoSearchDto.getBarcode();
        QueryWrapper<ErpBarcodePrintDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bar_code", barcode);
        if(null != ruleId){
            queryWrapper.eq("barcode_rule_id",ruleId);
        }
        queryWrapper.last("LIMIT 1");
        ErpBarcodePrintDetail erpBarcodePrintDetail = getOne(queryWrapper,false);
        return erpBarcodePrintDetail;
    }

    @Override
    public List<ErpBarcodePrintDetail> listByPrintId(Long printId) {
        QueryWrapper<ErpBarcodePrintDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("barcode_print_id",printId);
        List<ErpBarcodePrintDetail> barcodePrintDetails = list(queryWrapper);
        return barcodePrintDetails;
    }
}
